
<!DOCTYPE HTML>
<html lang="" >
    <head>
        <meta charset="UTF-8">
        <meta content="text/html; charset=utf-8" http-equiv="Content-Type">
        <title>3. 第一个路由 UsersController · GitBook</title>
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="description" content="">
        <meta name="generator" content="GitBook 3.2.2">
        
        
        
    
    <link rel="stylesheet" href="../gitbook/style.css">

    
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-highlight/website.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-search/search.css">
                
            
                
                <link rel="stylesheet" href="../gitbook/gitbook-plugin-fontsettings/website.css">
                
            
        

    

    
        
    
        
    
        
    
        
    
        
    
        
    

        
    
    
    <meta name="HandheldFriendly" content="true"/>
    <meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
    <meta name="apple-mobile-web-app-capable" content="yes">
    <meta name="apple-mobile-web-app-status-bar-style" content="black">
    <link rel="apple-touch-icon-precomposed" sizes="152x152" href="../gitbook/images/apple-touch-icon-precomposed-152.png">
    <link rel="shortcut icon" href="../gitbook/images/favicon.ico" type="image/x-icon">

    
    <link rel="next" href="4.html" />
    
    
    <link rel="prev" href="2.html" />
    

    </head>
    <body>
        
<div class="book">
    <div class="book-summary">
        
            
<div id="book-search-input" role="search">
    <input type="text" placeholder="Type to search" />
</div>

            
                <nav role="navigation">
                


<ul class="summary">
    
    

    

    
        
        <li class="header">内容</li>
        
        
    
        <li class="chapter " data-level="1.1" data-path="../">
            
                <a href="../">
            
                    
                    0. 介绍
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.2" data-path="1.html">
            
                <a href="1.html">
            
                    
                    1. php 开发环境安装
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.3" data-path="2.html">
            
                <a href="2.html">
            
                    
                    2. 跑 laravel 的 hello world
            
                </a>
            

            
        </li>
    
        <li class="chapter active" data-level="1.4" data-path="3.html">
            
                <a href="3.html">
            
                    
                    3. 第一个路由 UsersController
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.5" data-path="4.html">
            
                <a href="4.html">
            
                    
                    4. 在数据库中创建一条数据
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.6" data-path="5.html">
            
                <a href="5.html">
            
                    
                    5. 简单的用户认证
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.7" data-path="6.html">
            
                <a href="6.html">
            
                    
                    6. 修改 User model
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.8" data-path="7.html">
            
                <a href="7.html">
            
                    
                    7. User model 的 getter 方法
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.9" data-path="8.html">
            
                <a href="8.html">
            
                    
                    8. view 的更多知识
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.10" data-path="9.html">
            
                <a href="9.html">
            
                    
                    9. 在 view 中共享变量
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.11" data-path="10.html">
            
                <a href="10.html">
            
                    
                    10. blade layout
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.12" data-path="11.html">
            
                <a href="11.html">
            
                    
                    11. 使用 @include 来整理 view
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.13" data-path="12.html">
            
                <a href="12.html">
            
                    
                    12. Blade if/else/unless/or
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.14" data-path="13.html">
            
                <a href="13.html">
            
                    
                    13. factories, faker and seeding
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="1.15" data-path="14.html">
            
                <a href="14.html">
            
                    
                    14. Blade foreach
            
                </a>
            

            
        </li>
    

    
        
        <li class="header">其他</li>
        
        
    
        <li class="chapter " data-level="2.1" data-path="laravel_vim.html">
            
                <a href="laravel_vim.html">
            
                    
                    VIM 的 laravel 插件
            
                </a>
            

            
        </li>
    
        <li class="chapter " data-level="2.2" data-path="laravel_code_vim.html">
            
                <a href="laravel_code_vim.html">
            
                    
                    VIM 中有效地查看 php 源码
            
                </a>
            

            
        </li>
    

    

    <li class="divider"></li>

    <li>
        <a href="https://www.gitbook.com" target="blank" class="gitbook-link">
            Published with GitBook
        </a>
    </li>
</ul>


                </nav>
            
        
    </div>

    <div class="book-body">
        
            <div class="body-inner">
                
                    

<div class="book-header" role="navigation">
    

    <!-- Title -->
    <h1>
        <i class="fa fa-circle-o-notch fa-spin"></i>
        <a href=".." >3. 第一个路由 UsersController</a>
    </h1>
</div>




                    <div class="page-wrapper" tabindex="-1" role="main">
                        <div class="page-inner">
                            
<div id="book-search-results">
    <div class="search-noresults">
    
                                <section class="normal markdown-section">
                                
                                <blockquote>
<p>2017.08.09 &#x5185;&#x5BB9;&#x91CD;&#x65B0;&#x4FEE;&#x6539;&#x6574;&#x7406;&#xFF0C;&#x4EE3;&#x7801;&#x4F18;&#x5316;</p>
</blockquote>
<p>&#x6B63;&#x5982;&#x4E0A;&#x4E00;&#x7BC7;<a href="https://www.rails365.net/articles/ruby-cheng-xu-yuan-xue-xi-laravel-kuang-jia-bi-ji-2-pao-laravel-de-hello-world" target="_blank">Ruby &#x7A0B;&#x5E8F;&#x5458;&#x5B66;&#x4E60; laravel &#x6846;&#x67B6;&#x7B14;&#x8BB0; (2)-&#x8DD1; laravel &#x7684; hello world</a>&#x6240;&#x8BF4;&#x7684;&#x90A3;&#x6837;&#xFF0C;&#x5DF2;&#x7ECF;&#x628A;&#x9879;&#x76EE;&#x7684;hello world&#x8DD1;&#x8D77;&#x6765;&#x4E86;&#xFF0C;&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x8981;&#x6539;&#x5B83;&#x7684;&#x9996;&#x9875;&#x5185;&#x5BB9;&#x3002;</p>
<p>&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x5728;&#x9879;&#x76EE;&#x6587;&#x4EF6;&#x4E2D;<code>resources/views/welcome.blade.php</code>&#x3002;</p>
<p>&#x91CC;&#x9762;&#x662F;&#x4E00;&#x4E9B;&#x9759;&#x6001;&#x7684;html&#xFF0C;&#x52A0;&#x4E0A;&#x4E00;&#x4E9B;php&#x4EE3;&#x7801;&#x6DF7;&#x5728;&#x4E00;&#x8D77;&#x3002;</p>
<p>&#x5F88;&#x7B80;&#x5355;&#xFF0C;&#x4F60;&#x6253;&#x5F00;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#xFF0C;&#x5C31;&#x53EF;&#x4EE5;&#x4FEE;&#x6539;&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x4E86;&#x3002;</p>
<p>&#x6709;&#x4E00;&#x4E2A;&#x5730;&#x65B9;&#x5B9A;&#x4E49;&#x4E86;&#x8FD9;&#x4E2A;&#x9996;&#x9875;&#x7684;&#x8DEF;&#x7531;&#xFF0C;&#x662F;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#xFF1A;<code>routes/web.php</code></p>
<p>&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-php"><span class="hljs-comment">// routes/web.php</span>

<span class="hljs-meta">&lt;?php</span>

...

Route::get(<span class="hljs-string">&apos;/&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">()</span> </span>{
    <span class="hljs-keyword">return</span> view(<span class="hljs-string">&apos;welcome&apos;</span>);
});
</code></pre>
<p>&#x8FD9;&#x662F;&#x4E2A;&#x5B9A;&#x4E49;&#x8DEF;&#x7531;&#x7684;&#x6587;&#x4EF6;&#x3002;</p>
<p>&#x4F60;&#x53EF;&#x80FD;&#x4F1A;&#x601D;&#x8003;&#xFF0C;&#x5F53;&#x6267;&#x884C;<code>view(&apos;welcome&apos;)</code>&#x4E3A;&#x4EC0;&#x4E48;&#x5C31;&#x4F1A;&#x53BB;&#x627E;<code>resources/views/welcome.blade.php</code>&#x5462;&#xFF1F;</p>
<p>&#x539F;&#x6765;&#x6709;&#x4E2A;&#x6587;&#x4EF6;&#x5B9A;&#x4E49;&#x4E86;&#xFF0C;&#x662F;&#x8FD9;&#x4E2A;&#x6587;&#x4EF6;&#xFF1A;<code>config/view.php</code>&#x3002;</p>
<pre><code class="lang-php"><span class="hljs-comment">// config/view.php</span>

<span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">return</span> [

    <span class="hljs-comment">// &#x4E3B;&#x8981;&#x662F;&#x8FD9;&#x90E8;&#x5206;</span>
    <span class="hljs-string">&apos;paths&apos;</span> =&gt; [
        resource_path(<span class="hljs-string">&apos;views&apos;</span>),
    ],



    <span class="hljs-string">&apos;compiled&apos;</span> =&gt; realpath(storage_path(<span class="hljs-string">&apos;framework/views&apos;</span>)),

];
</code></pre>
<p>&#x628A;<code>resource_path(&apos;views&apos;)</code>&#x7684;&#x5185;&#x5BB9;&#x8F93;&#x51FA;&#x6765;&#x5C31;&#x662F;<code>resources/views/welcome.blade.php</code>&#x8FD9;&#x4E2A;view&#x6587;&#x4EF6;&#x7684;&#x7EDD;&#x5BF9;&#x8DEF;&#x5F84;&#x4E86;&#x3002;</p>
<h2 id="1-&#x4FEE;&#x6539;&#x8DEF;&#x7531;">1. &#x4FEE;&#x6539;&#x8DEF;&#x7531;</h2>
<p>&#x627E;&#x5230;<code>routes/web.php</code>&#x6587;&#x4EF6;&#xFF0C;&#x6DFB;&#x52A0;&#x5982;&#x4E0B;&#x5185;&#x5BB9;&#xFF1A;</p>
<pre><code class="lang-php"><span class="hljs-meta">&lt;?php</span>
...

Route::get(<span class="hljs-string">&apos;/users&apos;</span>, <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-params">()</span> </span>{
    <span class="hljs-comment">// &#x8FD9;&#x91CC;&#x5B9A;&#x4E49;&#x4E86;$users&#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#xFF0C;&#x5185;&#x5BB9;&#x662F;&#x4E2A;&#x6570;&#x7EC4;</span>
    $users = [
            <span class="hljs-string">&apos;0&apos;</span> =&gt; [
                <span class="hljs-string">&apos;first_name&apos;</span> =&gt; <span class="hljs-string">&apos;Renato&apos;</span>,
                <span class="hljs-string">&apos;last_name&apos;</span> =&gt; <span class="hljs-string">&apos;Hysa&apos;</span>
            ],
            <span class="hljs-string">&apos;1&apos;</span> =&gt; [
                <span class="hljs-string">&apos;first_name&apos;</span> =&gt; <span class="hljs-string">&apos;Jessica&apos;</span>,
                <span class="hljs-string">&apos;last_name&apos;</span> =&gt; <span class="hljs-string">&apos;Alba&apos;</span>
            ]
        ];
    <span class="hljs-keyword">return</span> $users;
});
</code></pre>
<p>&#x7136;&#x540E;&#x6253;&#x5F00;&#x6D4F;&#x89C8;&#x5668;&#xFF0C;&#x8F93;&#x5165;&#xFF1A;<code>http://127.0.0.1:8000/users</code>&#xFF0C;&#x5982;&#x4E0B;&#x56FE;&#x6240;&#x793A;</p>
<p><img src="https://rails365.oss-cn-shenzhen.aliyuncs.com/uploads/photo/image/271/2017/e3ed719ad1fb4db358e6ee71dc68cd5d.png" alt=""></p>
<p>&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x8F93;&#x51FA;&#x4E86;<code>$users</code>&#x53D8;&#x91CF;&#x7684;&#x5185;&#x5BB9;&#x3002;</p>
<p>&#x4E00;&#x822C;&#x6765;&#x8BF4;&#xFF0C;&#x6211;&#x4EEC;&#x4E0D;&#x4F1A;&#x5728;&#x8DEF;&#x7531;&#x4E2D;&#x653E;&#x592A;&#x591A;&#x903B;&#x8F91;&#xFF0C;&#x6211;&#x4EEC;&#x5E94;&#x8BE5;&#x628A;&#x8FD9;&#x4E9B;&#x903B;&#x8F91;&#x653E;&#x5230;controller&#x4E2D;&#x3002;</p>
<h2 id="2-&#x4F7F;&#x7528;-php-artisan-&#x6765;&#x521B;&#x5EFA;-controller">2. &#x4F7F;&#x7528; php artisan &#x6765;&#x521B;&#x5EFA; controller</h2>
<p>&#x50CF;rails&#x90A3;&#x6837;&#x7684;&#xFF0C;&#x6211;&#x4EEC;&#x53EF;&#x4EE5;&#x7528;&#x547D;&#x4EE4;&#x6765;&#x751F;&#x6210;&#x4E00;&#x4E2A;controller&#xFF0C;&#x800C;&#x8FD9;&#x4E2A;&#x547D;&#x4EE4;&#x5C31;&#x662F;<code>php artisan</code>&#x3002;</p>
<p>&#x4F60;&#x5728;&#x7EC8;&#x7AEF;&#x4E0A;&#x8F93;&#x5165;<code>php artisan</code>&#x5E76;&#x56DE;&#x8F66;&#xFF0C;&#x53EF;&#x4EE5;&#x770B;&#x5230;&#x5B83;&#x6709;&#x5F88;&#x591A;&#x5B50;&#x547D;&#x4EE4;&#x3002;</p>
<p><img src="https://rails365.oss-cn-shenzhen.aliyuncs.com/uploads/photo/image/272/2017/92646da92fd11d259e75e67762ecf75d.png" alt=""></p>
<p>&#x73B0;&#x5728;&#x6211;&#x4EEC;&#x8981;&#x4F7F;&#x7528;<code>make:controller</code>&#x8FD9;&#x4E2A;&#x5B50;&#x547D;&#x4EE4;&#x3002;</p>
<pre><code class="lang-bash">php artisan make:controller UsersController
</code></pre>
<p>&#x7EC8;&#x7AEF;&#x4E0A;&#x4F1A;&#x63D0;&#x793A;&#xFF1A;</p>
<pre><code>Controller created successfully.
</code></pre><p>&#x8868;&#x793A;&#x6210;&#x529F;&#x521B;&#x5EFA;&#x4E86;users&#x8FD9;&#x4E2A;controller&#xFF0C;&#x6587;&#x4EF6;&#x4F4D;&#x4E8E;<code>app/Http/Controllers/UsersController.php</code>&#x3002;</p>
<p>&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-php"><span class="hljs-comment">// app/Http/Controllers/UsersController.php</span>

<span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UsersController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-comment">//</span>
}
</code></pre>
<p>&#x6211;&#x628A;&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x4FEE;&#x6539;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-php"><span class="hljs-comment">// app/Http/Controllers/UsersController.php</span>

<span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UsersController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-comment">// &#x8FD9;&#x90E8;&#x5206;&#x662F;&#x65B0;&#x589E;&#x7684;</span>
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span><span class="hljs-params">()</span>
    </span>{
        $users = [
            <span class="hljs-string">&apos;0&apos;</span> =&gt; [
                <span class="hljs-string">&apos;first_name&apos;</span> =&gt; <span class="hljs-string">&apos;Renato&apos;</span>,
                <span class="hljs-string">&apos;last_name&apos;</span> =&gt; <span class="hljs-string">&apos;Hysa&apos;</span>
            ],
            <span class="hljs-string">&apos;1&apos;</span> =&gt; [
                <span class="hljs-string">&apos;first_name&apos;</span> =&gt; <span class="hljs-string">&apos;Jessica&apos;</span>,
                <span class="hljs-string">&apos;last_name&apos;</span> =&gt; <span class="hljs-string">&apos;Alba&apos;</span>
            ]
        ];
        <span class="hljs-keyword">return</span> $users;
    }
}
</code></pre>
<p>&#x5C31;&#x662F;&#x6DFB;&#x52A0;&#x4E86;&#x4E00;&#x4E2A; <code>index</code> action&#xFF0C;&#x5185;&#x5BB9;&#x8DDF;&#x4E4B;&#x524D;&#x7684;&#x4E00;&#x6837;&#x3002;</p>
<p>&#x6700;&#x540E;&#xFF0C;&#x8DEF;&#x7531;&#x8981;&#x91CD;&#x65B0;&#x6307;&#x5411;&#x5230;&#x8FD9;&#x4E2A;&#x65B0;&#x521B;&#x5EFA;&#x7684;controller&#x548C;action&#x4E2D;&#xFF0C;&#x6240;&#x4EE5;&#x8981;&#x8DDF;&#x7740;&#x53D8;&#x4E00;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-php"><span class="hljs-comment">// routes/web.php</span>
<span class="hljs-meta">&lt;?</span> php

...

Route::get(<span class="hljs-string">&apos;/users&apos;</span>, <span class="hljs-string">&apos;UsersController@index&apos;</span>);
</code></pre>
<p>&#x6D4F;&#x89C8;&#x5668;&#x8FD8;&#x662F;&#x4F1A;&#x8F93;&#x51FA;&#x8DDF;&#x539F;&#x6765;&#x4E00;&#x6837;&#x7684;&#x5185;&#x5BB9;&#x3002;</p>
<h2 id="3-&#x4F7F;&#x7528;view">3. &#x4F7F;&#x7528;view</h2>
<p>&#x5728;&#x5B9E;&#x9645;&#x5F00;&#x53D1;&#x4E2D;&#xFF0C;controller&#x5E94;&#x8BE5;&#x653E;&#x4E00;&#x4E9B;&#x4E1A;&#x52A1;&#x903B;&#x8F91;&#x7684;&#x5185;&#x5BB9;&#xFF0C;&#x6BD4;&#x5982;&#x67E5;&#x627E;&#x6570;&#x636E;&#x5E93;&#x3001;&#x53D6;&#x4E00;&#x4E9B;&#x53D8;&#x91CF;&#x4E4B;&#x7C7B;&#xFF0C;&#x800C;&#x8981;&#x5448;&#x73B0;&#x7ED9;&#x7528;&#x6237;&#x7684;&#x6570;&#x636E;&#x5E94;&#x8BE5;&#x653E;&#x5728;view&#x4E2D;&#x3002;</p>
<p>&#x6211;&#x4EEC;&#x628A;&#x539F;&#x672C;&#x5728;controller&#x7684;<code>$users</code>&#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x7684;&#x5185;&#x5BB9;&#x653E;&#x5230;view&#x4E2D;&#x3002;</p>
<p>&#x4E4B;&#x524D;&#x7684;<code>index</code>&#x65B9;&#x6CD5;&#x91CC;&#x7684;<code>return $users;</code>&#x6539;&#x6210;<code>return view(&apos;admin.users.index&apos;, compact(&apos;users&apos;));</code>&#x3002;</p>
<p>&#x5982;&#x4E0B;&#x6240;&#x793A;&#xFF1A;</p>
<pre><code class="lang-php"><span class="hljs-comment">// app/Http/Controllers/UsersController.php</span>

<span class="hljs-meta">&lt;?php</span>

<span class="hljs-keyword">namespace</span> <span class="hljs-title">App</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Controllers</span>;

<span class="hljs-keyword">use</span> <span class="hljs-title">Illuminate</span>\<span class="hljs-title">Http</span>\<span class="hljs-title">Request</span>;

<span class="hljs-class"><span class="hljs-keyword">class</span> <span class="hljs-title">UsersController</span> <span class="hljs-keyword">extends</span> <span class="hljs-title">Controller</span>
</span>{
    <span class="hljs-keyword">public</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">index</span><span class="hljs-params">()</span>
    </span>{
        $users = [
            <span class="hljs-string">&apos;0&apos;</span> =&gt; [
                <span class="hljs-string">&apos;first_name&apos;</span> =&gt; <span class="hljs-string">&apos;Renato&apos;</span>,
                <span class="hljs-string">&apos;last_name&apos;</span> =&gt; <span class="hljs-string">&apos;Hysa&apos;</span>
            ],
            <span class="hljs-string">&apos;1&apos;</span> =&gt; [
                <span class="hljs-string">&apos;first_name&apos;</span> =&gt; <span class="hljs-string">&apos;Jessica&apos;</span>,
                <span class="hljs-string">&apos;last_name&apos;</span> =&gt; <span class="hljs-string">&apos;Alba&apos;</span>
            ]
        ];

        <span class="hljs-comment">// &#x8FD9;&#x884C;&#x53D8;&#x4E86;&#xFF0C;&#x8868;&#x793A; $users &#x8FD9;&#x4E2A;&#x53D8;&#x91CF;&#x4F1A;&#x4F20;&#x9012;&#x5230;view&#x4E2D;</span>
        <span class="hljs-keyword">return</span> view(<span class="hljs-string">&apos;admin.users.index&apos;</span>, compact(<span class="hljs-string">&apos;users&apos;</span>));
    }
}
</code></pre>
<p>&#x7136;&#x540E;&#x627E;&#x5230;<code>resources/views</code>&#x76EE;&#x5F55;&#xFF0C;&#x518D;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;<code>admin</code>&#x76EE;&#x5F55;&#xFF0C;&#x518D;&#x5728;<code>admin</code>&#x76EE;&#x5F55;&#x4E0B;&#x65B0;&#x5EFA;<code>users</code>&#x76EE;&#x5F55;&#x3002;</p>
<p>&#x6700;&#x540E;&#x65B0;&#x5EFA;&#x4E00;&#x4E2A;<code>index.blade.php</code>&#x6587;&#x4EF6;&#xFF0C;&#x4F4D;&#x4E8E;<code>resources/views/admin/users/index.blade.php</code></p>
<pre><code>resources/views/admin
&#x2514;&#x2500;&#x2500; users
    &#x2514;&#x2500;&#x2500; index.blade.php
</code></pre><p>&#x5B83;&#x7684;&#x5185;&#x5BB9;&#x5982;&#x4E0B;&#xFF1A;</p>
<pre><code class="lang-php">&lt;ul&gt;
    @<span class="hljs-keyword">foreach</span>($users <span class="hljs-keyword">as</span> $user)
        &lt;li&gt;{{ $user[<span class="hljs-string">&apos;first_name&apos;</span>] }} {{ $user[<span class="hljs-string">&apos;last_name&apos;</span>] }}&lt;/li&gt;
    @<span class="hljs-keyword">endforeach</span>
&lt;/ul&gt;
</code></pre>
<p>&#x6700;&#x540E;&#x5728;&#x6D4F;&#x89C8;&#x5668;&#x4E2D;&#x8F93;&#x5165; <code>http://127.0.0.1:8000/users</code> &#x8F93;&#x51FA;&#x5982;&#x4E0B;&#xFF1A;</p>
<p><img src="https://rails365.oss-cn-shenzhen.aliyuncs.com/uploads/photo/image/273/2017/f7f08c10efad619c6f38ceb804824e4b.png" alt=""></p>
<p>&#x5B8C;&#x7ED3;&#x3002;</p>
<p>&#x4E0B;&#x4E00;&#x7BC7;&#xFF1A;<a href="https://www.rails365.net/articles/ruby-cheng-xu-yuan-xue-xi-laravel-kuang-jia-bi-ji-4-zai-shu-ju-ku-zhong-chuang-jian-yi-tiao-shu-ju" target="_blank">Ruby &#x7A0B;&#x5E8F;&#x5458;&#x5B66;&#x4E60; laravel &#x6846;&#x67B6;&#x7B14;&#x8BB0; (4)-&#x5728;&#x6570;&#x636E;&#x5E93;&#x4E2D;&#x521B;&#x5EFA;&#x4E00;&#x6761;&#x6570;&#x636E;</a></p>

                                
                                </section>
                            
    </div>
    <div class="search-results">
        <div class="has-results">
            
            <h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
            <ul class="search-results-list"></ul>
            
        </div>
        <div class="no-results">
            
            <h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
            
        </div>
    </div>
</div>

                        </div>
                    </div>
                
            </div>

            
                
                <a href="2.html" class="navigation navigation-prev " aria-label="Previous page: 2. 跑 laravel 的 hello world">
                    <i class="fa fa-angle-left"></i>
                </a>
                
                
                <a href="4.html" class="navigation navigation-next " aria-label="Next page: 4. 在数据库中创建一条数据">
                    <i class="fa fa-angle-right"></i>
                </a>
                
            
        
    </div>

    <script>
        var gitbook = gitbook || [];
        gitbook.push(function() {
            gitbook.page.hasChanged({"page":{"title":"3. 第一个路由 UsersController","level":"1.4","depth":1,"next":{"title":"4. 在数据库中创建一条数据","level":"1.5","depth":1,"path":"chapters/4.md","ref":"chapters/4.md","articles":[]},"previous":{"title":"2. 跑 laravel 的 hello world","level":"1.3","depth":1,"path":"chapters/2.md","ref":"chapters/2.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"maxIndexSize":1000000,"ignoreSpecialCharacters":false},"sharing":{"facebook":true,"twitter":true,"google":false,"weibo":false,"instapaper":false,"vk":false,"all":["facebook","google","twitter","weibo","instapaper"]},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","pdf":"styles/pdf.css","epub":"styles/epub.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css"}},"file":{"path":"chapters/3.md","mtime":"2017-09-02T01:53:51.000Z","type":"markdown"},"gitbook":{"version":"3.2.2","time":"2017-09-02T01:57:53.635Z"},"basePath":"..","book":{"language":""}});
        });
    </script>
</div>

        
    <script src="../gitbook/gitbook.js"></script>
    <script src="../gitbook/theme.js"></script>
    
        
        <script src="../gitbook/gitbook-plugin-livereload/plugin.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search-engine.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-search/search.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-sharing/buttons.js"></script>
        
    
        
        <script src="../gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
        
    

    </body>
</html>

